const { ccclass, property } = cc._decorator
@ccclass
export class barpre extends cc.Component {
  gameNode: cc.Node
  gameScript: any
  currentSpeed = null
  onLoad() {
    const index = 'game816'
    this.gameNode = cc.find(`Canvas/gamePanel/gameNode/${index}`)
    this.gameScript = cc.find(`Canvas/gamePanel/gameNode/${index}`).getComponent(index)
    this.node.runAction(cc.sequence(cc.moveTo(2, 500, this.node.y), cc.moveTo(2, -500, this.node.y)).repeatForever())
  }
  onBeginContact(collider: cc.PhysicsContact, self: cc.PhysicsCollider, other: cc.PhysicsCollider) {
    if ((self.tag == 10 || self.tag == 0) && other.tag == 80 && !self.node['ishit']) {
      this.gameNode.emit('checkGameOver')
      return
    }
    if (self.tag == 10 && other.tag == 10) {
      this.gameNode.emit('checkGameOver')
    } else if (!self.node['onceonce']) {
      self.node['onceonce'] = true
      this.gameNode.emit('onhit', self.node['type'])
    }
    if (!self.node['ishit']) {
      self.node['ishit'] = true
    }
  }
}
